home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0046_Event Handling in Turbo Vision.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  94 lines

  1. {
  2. > I got a problem here. This procedure below ,derived from Tapplication, is
  3. > just idling. It won't do the command assigned to Pbutton. There's something
  4. > missing (I'm new with programming in Turbo Vision). The only things it does
  5. > it's to show my button and close my window back. The commands are defined
  6. > in > the HandleEvent of the Tapplication. My objective is to be able to
  7. > open a new > PDialog on top of this one by the command selected.
  8.  
  9. Your problem is the way you are implementing your dialog. There is no
  10. handleevent method to handle the events of the buttons. Create a tdialog
  11. and fully define and flesh it out, and then execute it from the application.
  12. }
  13.  
  14. Program ButtonTester; {Tested}
  15. Uses App,Objects,Drivers,Views,Dialogs,msgbox;
  16. Type
  17.    SelDialog = Object(TDialog)
  18.                  Constructor Init(var bounds:TRect;ATitle:TTitleStr);
  19.                  Procedure HandleEvent(var Event:TEvent); virtual;
  20.                end;
  21.    SelDialogPtr = ^SelDialog;
  22. Const
  23.   cmCD_Roms      = 100;
  24.   cmDiskets      = 101;
  25.   cmHard_drive   = 102;
  26.   cmMemory       = 103;
  27.  
  28. Constructor SelDialog.Init(var bounds:TRect;ATitle:TTitleStr);
  29.    var r : trect;
  30.    Begin
  31.      inherited init(Bounds,ATitle);
  32.      getextent(r); r.grow(-2,-2); r.b.y := r.a.y + 2;
  33.      insert(new(PButton,init(r,'~C~D Roms',cmCD_Roms,bfnormal)));
  34.      inc(r.a.y,2); inc(r.b.y,2);
  35.      insert(new(PButton,init(r,'~D~iskettes',cmDiskets,bfnormal)));
  36.      inc(r.a.y,2); inc(r.b.y,2);
  37.      insert(new(PButton,init(r,'~H~ard Drives',cmHard_Drive,bfnormal)));
  38.      inc(r.a.y,2); inc(r.b.y,2);
  39.      insert(new(PButton,init(r,'~M~emory',cmMemory,bfnormal)));
  40.   End;
  41. Procedure SelDialog.HandleEvent(var Event:TEvent);
  42.    Begin
  43.      inherited HandleEvent(Event);
  44.      if   (event.what = evcommand) and
  45.           (event.command in [cmCD_Roms,cmDiskets,cmHard_Drive,cmMemory])
  46.      then EndModal(event.command);
  47.    End;
  48.  
  49. Type
  50.   MyApp = Object(TApplication)
  51.             procedure run; virtual;
  52.             function GetSelection:word;
  53.           end;
  54.  
  55. Function MyApp.GetSelection:Word;
  56.    var p:SelDialogPtr;
  57.        r:Trect;
  58.    Begin
  59.      r.assign(0,0,30,11);
  60.      new(p,init(r,'Select [esc to quit]'));
  61.      p^.options := p^.options or ofCentered;
  62.      if   p <> nil
  63.      then begin
  64.             GetSelection := ExecView(p);
  65.             dispose(p,done);
  66.           end
  67.      else GetSelection := 0;
  68.    End;
  69.  
  70. Procedure MyApp.Run;
  71.    var w   :word;
  72.        stop:boolean;
  73.    Begin
  74.      stop := false;
  75.      Repeat
  76.        w := GetSelection;
  77.        case w of
  78.        cmCD_Roms    : messagebox(#3'Selected CD Roms',nil,mfokbutton);
  79.        cmDiskets    : messagebox(#3'Selected Diskettes',nil,mfokbutton);
  80.        cmHard_drive : messagebox(#3'Selected Hard Drives',nil,mfokbutton);
  81.        cmMemory     : messagebox(#3'Selected Memory',nil,mfokbutton);
  82.        else stop := true;
  83.       end;
  84.     Until Stop;
  85.   End;
  86.  
  87. Var mApp : MyApp;
  88.     m   : Longint;
  89. Begin
  90.   m := memavail;
  91.   with mApp do begin init; run; done; end;
  92.   if m <> memavail then writeln('heap ''a trouble');
  93. End.
  94.